package com.gdth.core.widget;

import com.gdth.R;
import com.gdth.utils.TimerInstance;
import com.gdth.widget.dialog.DialogLoader;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

/**
 * 
 * @author Arvin
 *
 */
public class BaseActivity extends Activity{
	/** 提示框 */
    public DialogLoader mDialogLoader;
    
	public void setContentView(int layoutResID) {
		super.setContentView(layoutResID);
		
		initInjectedView(this);
		
	    setStatusBar();
	    
	    init();
	    
	}

	protected void setStatusBar() {
	    StatusBarUtil.setColor(this, getResources().getColor(R.color.bank_header), 1);
	}

	public void setContentView(View view, LayoutParams params) {
		super.setContentView(view, params);
		
		initInjectedView(this);
		
		init();
	}

	public void setContentView(View view) {
		super.setContentView(view);
		
		initInjectedView(this);
		
		init();
	}
	
	public static void initInjectedView(Activity activity){ 
		AnnotationUtil.initInjectedView(activity, activity.getWindow().getDecorView());
	}
	
	private void init(){
		mDialogLoader = new DialogLoader(this);
		mDialogLoader.setMessage("加载中，请稍后..");
		

	    BaseApplication.getApp().addActivity(this);
	}
	
	/**
	 * finishActivity
	 * @param v
	 */
	public void finishClick(View v){
		finish();
	}
	
	@Override  
    protected void onStart() {  
    	TimerInstance.getInstance().stop();
        super.onStart();  
    }  
      
    //Activity从后台重新回到前台时被调用  
    @Override  
    protected void onRestart() {  
    	TimerInstance.getInstance().stop();
        super.onRestart();  
    }
  
    //Activity创建或者从被覆盖、后台重新回到前台时被调用  
    @Override  
    protected void onResume() {  
        super.onResume();  
    }
    
  //Activity窗口获得或失去焦点时被调用,在onResume之后或onPause之后  
    /*@Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
        super.onWindowFocusChanged(hasFocus); 
        Log.i(TAG, "onWindowFocusChanged called."); 
    }*/  
      
    //Activity被覆盖到下面或者锁屏时被调用  
    @Override  
    protected void onPause() {
    	TimerInstance.getInstance().restart();
        super.onPause();  
        //有可能在执行完onPause或onStop后,系统资源紧张将Activity杀死,所以有必要在此保存持久数据  
    }

	public void showUploadOptions() {
		// TODO Auto-generated method stub
	}
	
}
